/*
 * 作者: 侯晓宇
 * 时间: 2017-02-04
 * 说明：
 * Copyright (c) 2016-2017 中研沃兮
 */
define(function(require) {

	var c = require('app/utils/CommonUtils');
	var dbu = require('app/utils/DBUtils');
	var r = {};


	r.initRoomLiveType = function() {
		var arr = [{
			"val": "1",
			"text": "视频直播"
		}, {
			"val": "2",
			"text": "PPT+语音"
		}];
		return arr;
	}
	r.initRoomPublicType = function() {
		var arr = [{
			"val": "0",
			"text": "私有"
		}, {
			"val": "1",
			"text": "公开"
		}];
		
//		, {
//			"val": "2",
//			"text": "公开加密"
//		}, {
//			"val": "3",
//			"text": "付费观看"
//		}];
		return arr;
	}
		
	r.initRoomCatalog = function(includeHot){
//		[{"val":"ce6a8705-7e41-4983-b2fc-d04c33edc83c","text":"全部"},{"val":"28dca0fb-ecc3-4ee1-bc63-cb1e78e7582a","text":"互联网"},{"val":"913259F3-3F12-4757-87DE-7AA6309BFAF6","text":"333"},{"val":"98F3883D-753C-467E-B8A3-D69344881F85","text":"tag1"}]
		var arr_str = dbu.kvget('roomcatalog');
		
		var arr = eval('(' + arr_str + ')');
		
		if(c.isNull(includeHot)){
			includeHot = false;
		}
		 
		if(includeHot){
			return arr;
		}else{
			return arr.splice(1,arr.length - 1);
		}
		 
	}
	r.saveRoomCatalog = function(ret){
//		ret
//		[{"uuid":"994d1271-32b8-4cc6-937a-e54e449514bd","name":"热门","ordernum":1,"app1":0,"app2":0,"app3":1,"app4":0,"app5":0,"app6":0,"app7":0,"app8":0,"app9":0,"app10":0},{"uuid":"ce6a8705-7e41-4983-b2fc-d04c33edc83c","name":"全部","ordernum":2,"app1":0,"app2":0,"app3":1,"app4":0,"app5":0,"app6":0,"app7":0,"app8":0,"app9":0,"app10":0},{"uuid":"28dca0fb-ecc3-4ee1-bc63-cb1e78e7582a","name":"互联网","ordernum":6,"app1":0,"app2":0,"app3":1,"app4":0,"app5":0,"app6":0,"app7":0,"app8":0,"app9":0,"app10":0},{"uuid":"913259F3-3F12-4757-87DE-7AA6309BFAF6","name":"333","ordernum":6,"app1":0,"app2":0,"app3":1,"app4":0,"app5":0,"app6":0,"app7":0,"app8":0,"app9":0,"app10":0},{"uuid":"98F3883D-753C-467E-B8A3-D69344881F85","name":"tag1","ordernum":7,"app1":0,"app2":0,"app3":1,"app4":0,"app5":0,"app6":0,"app7":0,"app8":0,"app9":0,"app10":0}]}
		var arr = [];
		var i = 0;
		for(;i<ret.length;i++){
			var e = {
				val:ret[i].uuid,
				text:ret[i].name
			}
			arr.push(e);
		}
		var a = JSON.stringify(arr);
		
		dbu.kvset('roomcatalog',a);
		
	}
	r.getItemInArrByVal = function(arr, val){
		var flag = false;
		var i = 0;
		for (; i < arr.length; i++) {
			if (arr[i].val == val) {
				flag = true;
				break;
			}
		}
		if (flag) {
			return arr[i];
		} else {
			return null;
		}
	}
	r.getItemInArrByText = function(arr,text) {
		
		var flag = false;
		var i = 0;
		for (; i < arr.length; i++) {
			if (arr[i].text == text) {
				flag = true;
				break;
			}
		}
		if (flag) {
			return arr[i];
		} else {
			return null;
		}
	};
	r.getRoomLiveTypeByText = function(text) {
		var arr = r.initRoomLiveType();
		return r.getItemInArrByText(arr,text);
	};
	r.getRoomPublicTypeByText = function(text) {
		var arr = r.initRoomPublicType();
		return r.getItemInArrByText(arr,text);
	};
	r.getRoomCatalogByText = function(text, includeHot) {
		var arr = r.initRoomCatalog(includeHot);
		return r.getItemInArrByText(arr,text);
	};

	r.getRoomLiveTypeTextByVal = function(val){
		var arr = r.initRoomLiveType();
		return r.getItemInArrByVal(arr,val);
	}

	r.getRoomPublicTypeTextByVal = function(val){
		var arr = r.initRoomPublicType();
		return r.getItemInArrByVal(arr,val);
	}

	return r;
});